define(['jquery'] , function(){
	//Date extra .
	Date.prototype.format = function(fmt){ 
	  var o = {   
	    "M+" : this.getMonth()+1,                 //月份   
	    "d+" : this.getDate(),                    //日   
	    "h+" : this.getHours(),                   //小时   
	    "m+" : this.getMinutes(),                 //分   
	    "s+" : this.getSeconds(),                 //秒   
	    "q+" : Math.floor((this.getMonth()+3)/3), //季度   
	    "S"  : this.getMilliseconds()             //毫秒   
	  };   
	  if(/(y+)/.test(fmt))   
		  fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));   
	  for(var k in o)   
		  if(new RegExp("("+ k +")").test(fmt))   
	  fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));   
	  return fmt;   
	}  
	
	Date.parse = function( input ){
		input = input.replace(/-/g , '/' ) ;
		return new Date( input ) ;
	}
	
	window.util = {
		uuid 	: 	function() {
		  var s = [];
		  var hexDigits = "0123456789abcdef";
		  for (var i = 0; i < 36; i++) 
		    s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
		  s[14] = "4";
		  s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
		  s[8] = s[13] = s[18] = s[23] = "-";
		  return s.join("") ;
		},
		clear 	: 	function( data , defaultValue ){
			for( var key in data )
				delete data[key] ;
			if( defaultValue )
				$.extend( true , data , defaultValue ) ;
		},
		format 	: 	function( format , data ){
			data = data || {} ;
			var formatMap = undefined , regexp = /(\$[a-zA-Z0-9_]+)/g ;
			while( rs = regexp.exec( format ) ){
				if( !formatMap ) formatMap = {} ;
				formatMap[ rs[0] ] = data[ rs[0].replace('$','') ] ;
			}
			if( !formatMap ) return format ;
			for( var key in formatMap ){
				var value = formatMap[key] ;
				if( typeof value == 'undefined' ){
					value = '' ;
				}
				format = format.replace(key , value ) ;
			}
			format = format.replace(/(\$[a-zA-Z0-9_]+)/g , '') ;
			return format ;
		},
		editableData : function( meta , data , e , option ){
			if( !data ) return {} ;
			var result = {} ;
			for( var i = 0 ; i < meta.length ; i ++ ){
				var sub = meta[i] ;
				if( sub instanceof Array ){
					$.extend( true , result , this.editableData( sub , data  , e , option ) ) ;
					continue ;
				}
				var value = data[sub['name'] ] ;
				if( !e && sub['editable'] === false )
					continue ;
				if( option && typeof option[ sub['name'] ] == 'function' )
					value = option[ sub['name'] ]( value , data ) ;
				result[ sub['name'] ] =  value ;
			}
			return result ;
		},
		fInA 	: 	function( array , field , fname ){
			fname = fname || 'name' ;
			if( !array || !(array instanceof Array) || !array.length  )
				return ;
			var result;
			for( var i = 0 ; i < array.length ; i ++ ){
				if( ( array[i] instanceof Array ) && 
						( result = this.fInA( array[i] , field , fname ) ) )
					return result ;
				else if( array[i][fname] == field )
					return array[i] ;
			}
			return ;	
		},
		reqParam 	: 	function(){
			var param = {} , strparam = location.href.split('?')[1];
			if( !strparam )
				return param ;
			var pair = strparam.split('&') ;
			for( var i = 0 ; i < pair.length ; i ++ ){
				var kv = pair[i].split('=') ;
				if( kv && kv.length > 1 )
					param[kv[0]] = kv[1] ;
			}
			return param ;
		}
	}
	return util ;
})